<?php
include dirname(dirname(__FILE__)).'/admin-verify.php';
include dirname(__FILE__).'/functions.php';
include dirname(dirname(__FILE__)).'/user-manage/functions.php';
$user_list = getAllUser();
$option_list = "";
foreach($user_list as $item) {
	$option_list.='<option value="'.$item['id'].'">'.$item['user_real_name'].'</option>';
}
$excellent_worker = getExcellentWorker();

?>

<html>
<head>
	<?php include dirname(dirname(dirname(__FILE__))).'/include/common-header.php'; ?>
	<?php 
		if(isset($_POST['submit'])) {
			$worker1_id = addslashes($_POST['excellent_worker1']);
			$worker2_id = addslashes($_POST['excellent_worker2']);
			$author_id = $_SESSION['user_id'];
			if(updateExcellentWorker($worker1_id,$worker2_id,$author_id)) {
				echo '<script type="text/javascript">alert("修改优秀员工成功！");
					 window.location="";</script>';
			}
		}
	?>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#submit").click(function() {
				$("form").submit();
			});
			<?php 
				if($excellent_worker['worker1_id']!='') {
					echo '$("#excellent_worker1 option[value=\''.$excellent_worker['worker1_id'].'\']").attr("selected","selected");';
				}
				if($excellent_worker['worker2_id']!='') {
					echo '$("#excellent_worker2 option[value=\''.$excellent_worker['worker2_id'].'\']").attr("selected","selected");';
				}
			?>
		});
	</script>
</head>
<body>
	<div class="col-md-12">
		<div>
			<h3>修改本月优秀员工</h3>
		</div>
		<div>
			<form  role="form" method="post" action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>>
				<div class="form-inline">
					优秀员工一<select class="form-control" name="excellent_worker1" id="excellent_worker1"
						style="margin-left:20px;margin-right:20px;">
						<?php 
							echo $option_list;
						?>
					</select>
					优秀员工二<select class="form-control" name="excellent_worker2" id="excellent_worker2"
						style="margin-left:20px;">
						<?php 
							echo $option_list;
						?>
					</select>
				</div>
				<button class="btn btn-primary" name="submit" id="submit" value="1" style="margin-top:40px;">确认修改</button>
			</form>
		</div>
	</div>
</body>
</html>